package leetcode.median;

import java.util.HashMap;

import leetcode.base.ListNode;

public class $1171_RemoveZeroSumSublists {
    public ListNode removeZeroSumSublists(ListNode head) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        HashMap<Integer, ListNode> map = new HashMap<>();
        int sum = 0;
        for (ListNode d = dummy; d != null;d= d.next) {
            sum += d.val;
            map.put(sum, d);
        }

        sum = 0;
        for (ListNode d = dummy; d != null;d= d.next) {
            sum += d.val;
            d.next = map.get(sum).next;
        }




        return dummy.next;
    }
}
